﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OracleClient;
public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = DateTime.Now.ToString();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if ((txtName.Text == "") || (TextBox1.Text == " "))
        {
            Response.Write("<script>alert('账号与密码不能为空')</script>");
        }
        else 
        {
            string name = txtName.Text;
            string pwd = TextBox1.Text;
            string connet = "Data Source=orcl;User ID=booksale;Password=Qwertyuiop1;Unicode=True";


            OracleConnection sqlCon = new OracleConnection(connet);
            sqlCon.Open();


            OracleCommand sqlComGet = new OracleCommand();
            sqlComGet.Connection = sqlCon;

            sqlComGet.CommandText = "select * from booksale.admin where 账号='" + name + "' and 密码='" + pwd + "'";
            OracleDataReader sqlDr = sqlComGet.ExecuteReader();

            if (sqlDr.Read())                                  //帐号和密码正确
            {
                Session["name"] = name;                      //用Session记录帐号

                Session["pwd"] = pwd;                //用Session记录密码

                Response.Redirect("master/index.aspx");
            }
            else                                              //帐号或密码错误
            {


                Response.Write("<script>window.alert('您输入的用户名或密码不正确')</script>");


                
            }
            sqlCon.Close();
        }
        
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        txtName.Text =" ";
        TextBox1.Text =" ";
    }
}